package EjerciciosNoBoletin2.Ex1;

import java.awt.Checkbox;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JCheckBox;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComboBox;

public class Ex1ItemListener implements ItemListener{

	private JComboBox combo;
	private JCheckBox checkBox1, checkBox2,checkBox3;
	private JCheckBoxMenuItem mcheck1,mcheck2,mcheck3;
	private ScrollDemo ventana;
	private ScrollDemo ventanadog;
	private ScrollDemo ventanacat;
	private ScrollDemo ventanabird;
	
	public Ex1ItemListener(){
		
	}
	public Ex1ItemListener(JCheckBox checkBox1, JCheckBox checkBox2, JCheckBox checkBox3, JCheckBoxMenuItem mcheck1, JCheckBoxMenuItem mcheck2, JCheckBoxMenuItem mcheck3){
		this.checkBox1 = checkBox1;
		this.checkBox2 = checkBox2;
		this.checkBox3 = checkBox3;
		this.mcheck1 = mcheck1;
		this.mcheck2 = mcheck2;
		this.mcheck3 = mcheck3;
	}

	@Override
	public void itemStateChanged(ItemEvent e) {
		// TODO Auto-generated method stub
		
		
			
			if (e.getSource() instanceof JComboBox){
				if( e.getStateChange() == 1 ){
				combo = (JComboBox)e.getSource();
				ventana = new ScrollDemo((String)combo.getSelectedItem());
				}
			}

			if (e.getSource().equals(checkBox1) || e.getSource().equals(mcheck1)){
				
				if( e.getStateChange() == 1 ){
					ventanadog = new ScrollDemo("dog");
				}else if (e.getStateChange() == 2){
					ventanadog.dispose();
				}
		    }
			
			if (e.getSource().equals(checkBox2) || e.getSource().equals(mcheck2)){
				if( e.getStateChange() == 1 ){
					ventanacat = new ScrollDemo("cat");
				}else if (e.getStateChange() == 2){
					ventanacat.dispose();
				}
		    }
			
			if (e.getSource().equals(checkBox3) || e.getSource().equals(mcheck3)){
				if( e.getStateChange() == 1 ){
					ventanabird = new ScrollDemo("bird");
				}else if (e.getStateChange() == 2){
					ventanabird.dispose();
				}
		    }
			

		
	}

}
